<script setup lang="ts">
import { ContentWrap } from '@/components/ContentWrap'
import { Search } from '@/components/Search'
// import { useI18n } from '@/hooks/web/useI18n'
import { Table } from '@/components/Table'

import { adminFaPastureListApi } from '@/api/fa/pasture'
import { useTable } from '@/hooks/web/useTableTest'
import {
  // h,
  reactive
} from 'vue'
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
// 获取字典
// import { useCache } from '@/hooks/web/useCache'
// const { wsCache } = useCache()
// const dict: any = wsCache.get('dict')
// 字典通过value获取label
// const getDictLabel = (type, value) => {
//   let data = dict[type].find((item) => {
//     return item.value == value
//   })
//   return data ? data.label : ''
// }

const { register, tableObject, methods } = useTable<
  {
    total: number
    list: any[]
  },
  any
>({
  getListApi: adminFaPastureListApi,
  response: {
    data: 'data',
    count: 'count'
  }
})

const { getList, setSearchParams } = methods

getList()

// const { t } = useI18n()
const crudSchemas = reactive<CrudSchema[]>([
  {
    field: 'id',
    label: '主键',
    fixed: 'left',
    width: 60,
    table: {
      show: true
    },
    form: {
      show: false
    },
    detail: {
      show: false
    }
  },
  {
    field: 'legal_name',
    label: '客户',
    // width: 150,
    search: {
      show: true
    }
  },
  {
    field: 'name',
    label: '类型',
    // width: 200,
    search: {
      show: true
    }
  },
  {
    field: 'address',
    label: '出库类型',
    // width: 150,
    search: {
      show: true
    }
  },
  {
    field: 'code',
    label: '入库类型',
    // width: 150,
    search: {
      show: true
    }
  },
  {
    field: 'creation_time',
    label: '创建时间',
    // width: 200,
    form: {
      show: true,
      component: 'DatePicker',
      componentProps: {
        disabled: true,
        type: 'datetime',
        valueFormat: 'YYYY-MM-DD HH:mm:ss'
      }
    },
    search: {
      show: true,
      component: 'DatePicker',
      componentProps: {
        'is-range': true,
        'unlink-panels': true,
        rangeSeparator: 'To',
        type: 'daterange',
        valueFormat: 'YYYY-MM-DD HH:mm:ss'
      }
    }
  },
  {
    field: 'operator_name',
    label: '备注',
    // width: 150,
    search: {
      show: false
    }
  }
  // {
  //   field: 'update_user_name',
  //   label: '创建人',
  //   width: 80,
  //   form: {
  //     show: false
  //   }
  // },
  // {
  //   field: 'action',
  //   fixed: 'right',
  //   label: t('tableDemo.action'),
  //   form: {
  //     show: false
  //   },
  //   detail: {
  //     show: false
  //   }
  // }
])

const { allSchemas } = useCrudSchemas(crudSchemas)
</script>

<template>
  <ContentWrap>
    <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />

    <Table
      v-model:pageSize="tableObject.pageSize"
      v-model:currentPage="tableObject.currentPage"
      :columns="allSchemas.tableColumns"
      :data="tableObject.tableList"
      :loading="tableObject.loading"
      :border="true"
      :pagination="{
        total: tableObject.count
      }"
      @register="register"
      :selection="true"
    />
  </ContentWrap>
</template>
